﻿CREATE PROCEDURE [dbo].[proc_Customer_CallOnTongJi_SubjoinView]
	(
		@DepartmentId int,
		@StartDate nvarchar(10),
		@EndDate nvarchar(10),
		@StartIndex int,
		@EndIndex int
	)
AS
Begin
	;WITH list As(Select ROW_NUMBER() OVER (ORDER BY cs.UpTime DESC)AS Row,
		cs.Id,
		cs.CustomerId,
		SubjoinId,
		[Description],
		UpName,
		UpTime,
		(Select Title From Customer_Subjoin Where Id=cs.SubjoinId) as SubjoinName,
		(Select CustomerName From Customer Where CustomerId=cs.CustomerId) as CustomerName,
		(Select EName From Employee Where UserName=cs.UpName) As EName
		From Customer_Subjoin_List cs
		Where cs.DepartmentId=@Departmentid and Convert(nchar(10),UpTime,120)>=@StartDate and Convert(nchar(10),UpTime,120)<=@EndDate 
	)
	--Select * From list Where Row between @StartIndex and @EndIndex
	Select *,(Select Count(0) From list) As RecordCount From list Where Row between @StartIndex and @EndIndex
End
	RETURN
